package com.telenav.module.map;

import android.content.Context;
import android.view.View;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapView;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.telenav.app.R;
import com.telenav.framework.network.HostProvider;
import com.telenav.mvc.AbstractBaseView;
import com.telenav.ui.AndroidDialog;
import com.telenav.ui.AndroidView;

public class SmartMapView extends AbstractBaseView implements ISmartMapConstants {

	private Context context;
	
	public SmartMapView(Context context)
	{
		this.context = context;
	}
	
	@Override
	protected AndroidDialog createDialogDelegate(int state) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected boolean updateDialog(int state, AndroidDialog dialog) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	protected AndroidView createViewDelegate(int state) {
		switch(state)
		{
		case STATE_INIT:
			return createMap();
		}
		return null;
	}

	@Override
	protected boolean updateViewDelegate(int state, AndroidView view) {
		// TODO Auto-generated method stub
		return false;
	}
	
	private AndroidView createMap()
	{
		BMapManager mBMapMan = new BMapManager(context);
		mBMapMan.init(HostProvider.API_KEY, null);
		View fullView = View.inflate(context, R.layout.yy_map, null);
		
		MapView mMapView = (MapView)fullView.findViewById(R.id.bmapsView);
		mMapView.setBuiltInZoomControls(true);
		
		//设置启用内置的缩放控件
		MapController mMapController = mMapView.getController();
		// 得到mMapView的控制权,可以用它控制和驱动平移和缩放
		GeoPoint point = new GeoPoint((int)(39.915* 1E6),(int)(116.404* 1E6));
		//用给定的经纬度构造一个GeoPoint，单位是微度 (度 * 1E6)
		mMapController.setCenter(point);//设置地图中心点
		mMapController.setZoom(12);//设置地图zoom级别
		
		return new AndroidView(fullView);
	}

}
